import xlrd
import xlwt

book = xlrd.open_workbook('../data/readAndWriteExcel.xlsx')
sheet = book.sheets()
bookList = list()
# 读取execl到list中
for sheetT in sheet:
    print('当前sheet数量', sheetT.nrows)
    print('当前sheet名字', sheetT.name)
    cols = sheetT.ncols
    rows = sheetT.nrows
    sheetTList = list()
    for n in list(range(rows)):
        rowList = list()
        for m in list(range(cols)):
            rowList.append(sheetT.cell(n, m).value)
        sheetTList.append(rowList)
    bookList.append(sheetTList)

print('当前book所有的sheet的数据, 三维数组', bookList)

workbook = xlwt.Workbook()
count = len(bookList)
for i in list(range(count)):
    worksheet1 = workbook.add_sheet('lch' + str(count) + '_1')
    worksheet2 = workbook.add_sheet('lch' + str(count) + '_2')
    worksheet3 = workbook.add_sheet('lch' + str(count) + '_3')
    sheetT = bookList[i]
    # 迭代每一行数据
    for j in list(range(len(sheetT))):
        # 迭代每一列
        sheetRow = sheetT[j]
        for k in list(range(len(sheetRow))):
            value = sheetRow[k]
            worksheet1.write(k, j, value)
            worksheet2.write(len(sheetT) - j - 1, len(sheetRow) - k - 1, value)
            worksheet3.write(len(sheetRow) - k - 1, len(sheetT) - j - 1, value)
workbook.save('../data/temp.xlsx')
